package com.shenglaotuan.community.common.config;

import com.shenglaotuan.community.common.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Resource
    private TokenInterceptor tokenInterceptor ;

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns(
                        "/user/**",
                        "/tag/**"
                ).excludePathPatterns(
                        "/user/code",
                        "/user/reg",
                        "/user/login"
                );
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        System.out.println("==========静态资源拦截！============");
        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/static/**/").addResourceLocations("classpath:/static/");
    }
}
